package com.firstcare.android_dylibrary.bean;

import com.alibaba.fastjson.JSONObject;
import com.firstcare.android_dylibrary.DYApplication;
import com.firstcare.android_dylibrary.bean.base.BaseModelProxy;
import com.firstcare.android_dylibrary.network.URLSet;
import com.firstcare.android_dylibrary.network.request.DYRequest;
import com.firstcare.android_dylibrary.network.request.ModelListRequest;
import com.rdxer.xxlibrary.HTTPUtils.listener.ErrorListener;
import com.rdxer.xxlibrary.HTTPUtils.listener.FailedListener;
import com.rdxer.xxlibrary.HTTPUtils.listener.OKListener;
import com.rdxer.xxlibrary.utils.Log;

import java.util.List;

/**
 * Created by chenyichao on 2016/8/30.
 */
public class WorkorderProxy extends BaseModelProxy<Workorder> {
    public  WorkorderProxy(){
    }
    /**
     *  不使用缓存
     */
    public static void getWorkorderProxyListNoCache(String text, int text1, final OKListener<List<WorkorderProxy>> okListener, FailedListener failedListener, ErrorListener errorListener) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("createTime",text);
        jsonObject.put("status",text1);
        ModelListRequest<WorkorderProxy> request = new ModelListRequest<WorkorderProxy>(URLSet.queryWorkList, jsonObject, okListener, failedListener, errorListener) {
            @Override
            protected Object getTargetData(JSONObject response) throws Exception{
                return response.getJSONObject("data").getJSONArray("esWorkorderList");
            }
        };
        DYApplication.getShared().getApi().addToRequestQueue(request);
    }
    /**
     * 更改名称
     *
     */
    public  void postWork( String id,final OKListener<Object> okListener, FailedListener failedListener, ErrorListener errorListener){
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("id",id);
        DYRequest<Object> request = new DYRequest<Object>(URLSet.manageWork, jsonObject, new OKListener<Object>() {
            @Override
            public void onOK(Object res, JSONObject response) {
                /// 登陆成功需要处理的事情
                Log.e(response);
                okListener.onOK(res,response);
            }
        }, failedListener, errorListener) {
            @Override
            protected Object getTargetData(JSONObject response) throws Exception {
                return response;
            }
        };
        DYApplication.getShared().getApi().addToRequestQueue(request);
    }
}
